# Maintainer: Antonio Rojas <arojas@archlinux.org>
# Contributor: Giovanni Scafora <giovanni@archlinux.org>
# Contributor: Henrik Ronellenfitsch <searinox@web.de>
# Contributor: Alessio Sergi <sergi.alessio {at} gmail.com>
# Contributor: Dario 'Dax' Vilardi <dax [at] deelab [dot] org>
# Contributor: Anatol Pomozov <anatol.pomozov@gmail.com>

pkgname=amule
epoch=1
pkgver=2.3.3
pkgrel=7
pkgdesc='An eMule-like client for ed2k p2p network'
arch=(loong64 x86_64)
url='http://www.amule.org'
license=(GPL)
depends=(wxwidgets-gtk3 geoip libupnp crypto++)
makedepends=(boost cmake gd)
provides=(amule-daemon)
source=(https://download.sourceforge.net/project/amule/aMule/$pkgver/aMule-$pkgver.tar.gz
        amuled.systemd amuleweb.systemd amule.sysusers amule.tmpfiles
        https://github.com/amule-project/amule/commit/9bcd201.patch
        https://github.com/amule-project/amule/commit/8085232.patch
        https://github.com/amule-project/amule/commit/f186b3a.patch
        https://github.com/amule-project/amule/commit/9e1d9eb.patch
        https://github.com/amule-project/amule/commit/d22e057.patch
        https://github.com/amule-project/amule/commit/a667c61.patch)
sha256sums=('fa85a054153c9787fce2d35a5c5590a3d390429b8fa0c5d8f9ea69e9904c7b72'
            '20ac6b60c5f3bf49c0b080dfc02409da3c9d01b154344188008c6a75ca69681e'
            'f4f43b1154ddccc9036a4291a58c6715f097b171fec62ea7aead0c9d9fa654f2'
            'c4ca658ab4105b3b90e0bb3efcc8121eca1c4d873787db1ed4f637925c16d502'
            'e9d1b7019c7075b0f8616c6507a767b87de8f899936680e9ff5829d8cbba224d'
            '3d5a852a20685022fa00b899d13a0fb34d20b59a7a7c6e24cade6ce2b4806bb4'
            '13f90b3aec3d9a5cb0bf6b1c59266bf45dabe6d0d500a8b7e596be29e5f93e83'
            '443f354611f356e9fe1132fd88812a21f9faad6bbcfdf61aa7a9462fdbdd161b'
            '2d63d92f0fc3c8a48591d6629bad1eee1b4c80526199a41eefdf4b059f99264f'
            'af9e8bee9363de10d3e8b4ef517c37d4c51c14bd781751c023fd2affd05d8768'
            'd702dbc1fc40ee0b9c209eaabf9ac1c9522d09c83647270ac7560d40d4906cdf')

prepare() {
  patch -d aMule-$pkgver -p1 < 9bcd201.patch # Fix translations install
  patch -d aMule-$pkgver -p1 < 8085232.patch
  patch -d aMule-$pkgver -p1 < f186b3a.patch
  patch -d aMule-$pkgver -p1 < d22e057.patch # Fix build
  patch -d aMule-$pkgver -p1 < 9e1d9eb.patch
  patch -d aMule-$pkgver -p1 < a667c61.patch # Install icons
}

build() {
  cmake -B build -S aMule-$pkgver \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DBUILD_ALC=ON \
    -DBUILD_ALCC=ON \
    -DBUILD_AMULECMD=ON \
    -DBUILD_CAS=ON \
    -DBUILD_DAEMON=ON \
    -DBUILD_REMOTEGUI=ON \
    -DBUILD_WEBSERVER=ON \
    -DBUILD_WXCAS=ON \
    -DBUILD_FILEVIEW=ON \
    -DENABLE_IP2COUNTRY=ON \
    -DENABLE_NLS=ON
  cmake --build build
}

package() {
  DESTDIR="$pkgdir" cmake --install build

  install -Dm644 "$srcdir"/amuled.systemd "$pkgdir"/usr/lib/systemd/system/amuled.service
  install -Dm644 "$srcdir"/amuleweb.systemd "$pkgdir"/usr/lib/systemd/system/amuleweb.service
  install -Dm644 "$srcdir"/amule.sysusers "$pkgdir"/usr/lib/sysusers.d/amule.conf
  install -Dm644 "$srcdir"/amule.tmpfiles "$pkgdir"/usr/lib/tmpfiles.d/amule.conf
}
